import axios from 'axios'

// 创建Axios实例
const request = axios.create({
    baseURL: 'http://localhost:8050', // 后端服务地址
    timeout: 5000
})

/**
 * 获取好友列表
 * @param userId 当前用户ID
 * @returns 好友列表
 */
export const getFriendList = (userId: number) => {
    return request.get('/relation/friends', {
        params: { userId }
    })

}
// 获取好友详情
export const getFriendDetail = (id: number) => {
    return request.get(`/relation/friend/detail/${id}`)
}
export const sendFriendRequest = (data: {
    fromUserId: number;
    toUserId: number;
    requestMsg: string; // 对应后端 request_msg 字段
}) => {
    return request.post('/friend/request', data);
};
// 搜索用户
export const searchUser = (keyword: string) =>
    request.get('/user/search', { params: { keyword } });
// 获取当前用户的待处理申请（status=0）
export const getNewFriendRequests = (toUserId: number) => {
    return request.get('/friend/requests', { params: { toUserId } });
};

// 同意申请
export const agreeRequest = (requestId: number) => {
    return request.put('/friend/agree', { requestId });
};

// 忽略申请
export const ignoreRequest = (requestId: number) => {
    return request.put('/friend/ignore', { requestId });
};